package com.ysd.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ysd.entity.Address;
import com.ysd.service.AddressService;
import com.ysd.util.Result;

@Controller
public class AddressController {

	@Autowired
	private AddressService addressService;
	
	@RequestMapping("getAddress")
	@ResponseBody
	public Object getAddress(int uid) {
		List<Address> list = addressService.findAddress(uid);
		return list;
	}
	
	@RequestMapping("deleteAddress")
	@ResponseBody
	public int deleteAddress(Address address) {
		int n = addressService.deleteAddress(address);
		return n;
	}

	
	@RequestMapping("addAddress")
	@ResponseBody
	public Object addAddress(Address address) {
		int n = addressService.addAddress(address);
		if (n>0) {
			return Result.toClient("0", "添加成功", null, n);
		} else {
			return Result.toClient("1", "添加失败", null, null);
		}
	}


	
	@RequestMapping("updateAddress")
	@ResponseBody
	public Object updateAddress(Address address) {
		int n = addressService.updateAddress(address);
		if (n>0) {
			return Result.toClient("0", "修改成功", null, n);
		} else {
			return Result.toClient("1", "修改失败", null, null);
		}
	}

	
	@RequestMapping("getRess")
	@ResponseBody
	public Object getRess(int id)  {
		List<Address> list = addressService.getRess(id);
		return list;
	}
	
	
}
